package com.education.user.controller;


import com.education.common.core.BaseController;
import com.education.common.core.TableDataInfo;
import com.education.common.poi.ExcelUtil;
import com.education.common.pojo.AjaxResult;
import com.education.user.pojo.SysInformation;
import com.education.user.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资讯 信息操作处理
 *
 * @author d
 * @date 2020-01-17
 */
@RestController
@RequestMapping("/k12main/sysInformation")
@CrossOrigin
public class SysInformationController extends BaseController {

    @Autowired
    private InformationService sysInformationService;

    /**
     * 查询资讯列表
     */
    @PostMapping("/list")
    public TableDataInfo list(SysInformation sysInformation) {
        startPage();
        List<SysInformation> list = sysInformationService.selectSysInformationList(sysInformation);
        return getDataTable(list);
    }

    /**
     * 导出资讯列表
     */
    @PostMapping("/export")
    public AjaxResult export(SysInformation sysInformation) {
        List<SysInformation> list = sysInformationService.selectSysInformationList(sysInformation);
        ExcelUtil<SysInformation> util = new ExcelUtil<SysInformation>(SysInformation. class);
        return util.exportExcel(list, "sysInformation");
    }


    /**
     * 新增保存资讯
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysInformation sysInformation) {
        return toAjax(sysInformationService.insertSysInformation(sysInformation));
    }


    /**
     * 修改保存资讯
     */
    @PostMapping("/edit")
    public AjaxResult editSave(SysInformation sysInformation) {
        return toAjax(sysInformationService.updateSysInformation(sysInformation));
    }

    /**
     * 删除资讯
     */
    @PostMapping("/del")
    public AjaxResult remove(String id) {
        return toAjax(sysInformationService.deleteSysInformationByIds(Integer.parseInt(id)));
    }
}